﻿Partial Class PrimTahsilat

	Public Sub GenericEventKisi(ByVal e As ProcessEventArgs)
		Select Case e.EventType
			Case EventType.Initialize
				Start("Prim tahsilatı", "Kişi bilgilerini girin.")
				sno = AddSigortali()
				donem = AddDonemIsv("donem", "Dönem", "", Today.AddMonths(-3).Year & (1 + Int((Today.AddMonths(-3).Month - 1) / 4)), "Dönemi seçmeniz gerekir")
				StartBody()
				AddList()
				Grid2 = List
				Grid2.LeftPanel.Width = 320
				Grid2.AddColumns("ay(Ay;40c),yil(Yıl;60c),ayadi(Ay;120l),basamak(Bas.;40c),*pek(PEK;80m),*pogs(PÖGS;40r),acik(Açıklama;100%l)")
				PrepareSummaryPanel()
			Case EventType.Shown
				Emanet = Nothing
				Grid2.Rows.Add(3)
			Case EventType.ValidateForm
				Dim DonemBas = New Date(donem.yil, (donem.ay - 1) * 3 + 1, 1)
				Dim brc = New db.prim.borcisveren(Remote, Input("sigortali"), DonemBas, DonemBas.AddMonths(3).AddDays(-1))
				'Borc = Prim.Borc.HesaplaIsveren(Remote, sno.get, CurrentDepartment, DonemBas, DonemBas.AddMonths(3).AddDays(-1), Remote.SysDate)
				If Check("Sigortali", Borc.ErrorMessage <> "", "!" & Borc.ErrorMessage) Then Return
				If Check("Sigortali", Borc.Aylar.Count = 0, "!Sigortalının ilgili döneme ait borcu bulunmadı.") Then Return
				ShowDialog("Isyeri")
			Case EventType.ButtonClicked
				Select Case e.Name
					Case "page0", "page1"
						If Tab = e.Name.Right(1) Then Return
						Tab = e.Name.Right(1)
						If Not Browser.Parent Is Nothing Then
							Browser.Parent.Controls.Remove(Browser)
						End If
						Restart()
				End Select
		End Select
	End Sub

	Private Sub Grid2_Propegate(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Grid2.Propegate
		Dim Cell = Grid2.CurrentCell
		e.Handled = True
		Select Case Cell.OwningColumn.Name
			Case "pek"
				Grid2.CurrentCell = Cell.OwningRow.Cells("pogs")
			Case "pogs"
				If Cell.RowIndex = 2 Then
					Buttons.Focus("Save")
				Else
					Grid2.CurrentCell = Grid2.Rows(Cell.RowIndex + 1).Cells("pek")
				End If
		End Select
	End Sub

#Region " Dialog İşyeri "

	Private Sub DialogIsyeri(e As ProcessEventArgs)
		Select Case e.EventType
			Case EventType.Initialize
				Modal.Start("Bordro seçimi", "Bordro türünü seçin.")
				Modal.AddList("", 640, 240)
			Case EventType.Shown
				Modal.List.AddColumns("isyeriadi(İşyeri adı;100%l),isyerino(İşyeri no.;100c),tehlike(Tehlike;50c),basamak(Basamak;60c),bordro(Bordro;50c)")
				For Each d In Borc.Donemler.Values
					Dim b = d.Aylar.First.Bordrolar.First
					Dim Rsi = Isyeri.IsyeriNoAra(Remote, b.isyeri)
					Modal.List.AddRow(Rsi("isyeriadi"), FormatIsyeriNo(Rsi("isyerino")), Rsi("tehlike"), b.basamak, b.tip)
				Next
			Case EventType.Activate
				IsverenGoster(Replace(Modal.List.SelectedRow("isyerino"), "/", ""), Modal.List.SelectedRow("bordro"))
				Modal.Close()
		End Select
	End Sub

	Dim SelectedIsyeri As String
	Private Sub IsverenGoster(isyerino As String, bordro As String)
		SelectedIsyeri = isyerino
		For i = 0 To 2
			Dim a = (donem.ay - 1) * 3 + i + 1
			Dim AyBordro = (From ay In Borc.Aylar.Values From b In ay.Bordrolar Where b.tip = bordro And b.tarih = New Date(donem.yil, a, 1) And b.isyeri = isyerino Select b).FirstOrDefault
			If Not AyBordro Is Nothing Then
				List.Rows(i).Cells("ay").Value = a
				List.Rows(i).Cells("ayadi").Value = MonthName(a)
				List.Rows(i).Cells("pogs").Value = AyBordro.pogs
				List.Rows(i).Cells("pek").Value = AyBordro.pek
				List.Rows(i).Cells("basamak").Value = AyBordro.basamak
			End If
		Next
		EnterDataStage()
		List.CurrentCell = List.Rows(0).Cells("pek")
		List.Focus()
		UpdateSummary()
	End Sub

#End Region

	Sub UpdateSummaryKisi()
		Dim Rsi = Isyeri.IsyeriNoAra(Local, SelectedIsyeri)
		Browser.Clear()
		Browser.Q("<body bgcolor=''><table cellpadding=3 cellspacing=1 width='100%' bgcolor='d0d8d0'>")
		Browser.Q("<tr bgcolor='ffffff'><td>@1</td><td>@2</td></tr>", "İşyeri no.", Rsi("isyerino"))
		Browser.Q("<tr bgcolor='ffffff'><td>@1</td><td>@2</td></tr>", "İşyeri adı", Rsi("isyeriadi"))
		If Not Emanet Is Nothing Then
			'If Not bordro.IsEmpty Then R1.Offset(0, 14)
			Browser.Q("<tr><td colspan=3>Emanet bilgileri</td></tr>")
			Browser.Q("<tr bgcolor='ffffff'><td>@1</td><td align=right>@2</td><td align=right>@3</td></tr>", "Emanet tarihi", "", "", DMY(Emanet.Tarih))
			Browser.Q("<tr bgcolor='ffffff'><td>@1</td><td align=right>@2</td><td align=right>@3</td></tr>", "Emanet no.", "", Emanet.EmanetNo)
			Browser.Q("<tr bgcolor='ffffff'><td>@1</td><td align=right>@2</td><td align=right>@3</td></tr>", "Emanet miktarı", "", Fm(Emanet.Miktar))
			Browser.Q("<tr bgcolor='ffffff'><td>@1</td><td align=right>@2</td><td align=right>@3</td></tr>", "Emanet kalan", "", Fm(Emanet.Kalan))
		End If
		Browser.Q("</table></body>")
	End Sub

End Class
